﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using Jzy.Workflow.Node;
using Jzy.Workflow.Task;

using Frame.Lib.Core.Base;

namespace Jzy.Workflow.Flow
{
    public class FlowDAL : BaseDAL
    {
        internal List<FlowInfo> GetList(string typeCode)
        {
            string sql = "select * from " + WFTableName.Flow + " where TypeCode=@p0";
            List<FlowInfo> list = dbOper.Query<FlowInfo>(sql, typeCode ?? "");
            return list;
        }

        internal object GetStartNodeID(object flowID)
        {
            string sql = "select ID from " + WFTableName.FlowNode + " where FlowID=@p0 and TypeID=@p1";

            object id = dbOper.GetScalar<int>(sql, flowID, (int)FlowNodeType.拟稿);
            return id;
        }

        /// <summary>
        /// 获得待办箱列表所对应的流程列表
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        internal List<FlowInfo> GetRequiredList(int userID)
        {
            string sql = "select * from " + WFTableName.Flow + " where ID in (select FlowID from " + WFTableName.FlowTask + " where State = " + (int)TaskState.待处理 + " and ReceiveID = @p0)";
            List<FlowInfo> list = dbOper.Query<FlowInfo>(sql, userID);
            return list;
        }
    }
}
